<?php
namespace Home\Model;

use Think\Model;

class Setting extends Model
{
	protected $tableName = 'setting';
	protected $_validate = array(
        array('name','require','用户名必须填写！',1),
        array('value','email','邮箱格式错误！',2),
        array('username','','用户名已经存在！',0,'unique',1),
    );

	public static function setOption($name, $value) {
		$setting = M('Setting');

		if ($setting->getByName($name)) {
			return $setting->where(['name'=>$name])->setField('value', $value);
		} else {
			$data['name'] = $name;
			$data['value'] = $value;
			return $setting->add($data);
		}
	}

	public static function getOption($name) {
		$setting = M('Setting');
		return $setting->getFieldByName($name,'value');
	}
}